package PTA;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) {
		ArrayList<String> list = new ArrayList<>();
		Set<String> word=new TreeSet<>();
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		while(!s.equals("!!!!!"))
		{
				list.add(s);
				word.add(s);
				s=sc.next();
		}
		System.out.println(word.size());
		Map<String, Integer> map=new TreeMap();
		for (String temp :word) {
			map.put(temp,Collections.frequency(list, temp));
		}
		ArrayList <Map.Entry<String,Integer>> list1 = new ArrayList<Map.Entry<String,Integer>>(map.entrySet());
		Collections.sort(list1,new Comparator<Map.Entry<String,Integer>>() {
			@Override
			public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) {
				// TODO Auto-generated method stub
				return o2.getValue().compareTo(o1.getValue());
			}
		});
	    for (int i = 0; i < 10; i++) {
	    	System.out.println(list1.get(i));
		}
			
	}

}
